package com.sreader.sreader4j;

import java.util.Locale;

import junit.textui.ResultPrinter;

import com.sreader.logic.InterpretationLogic;
import com.sreader.logic.NombresCalculer.nombreType;
import com.vaadin.ui.AbsoluteLayout;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.Window;

public class FeuilleDeResultatCroise extends CustomComponent{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Window mainWindow;
	private Locale currentLocaleValue;
	private InterpretationLogic interpret;
	private PersonBean firstPerson;
	private PersonBean secondPerson;
	private AbsoluteLayout mainLayout;
	private Panel mainPanel; 
	private Label resultLabel;
	private Label sourceLabel;
	private Messages messages;
	
	public FeuilleDeResultatCroise(Locale defaultLocale, Window main) {
		this.mainWindow = main;
		this.currentLocaleValue = defaultLocale;
		setMessages(new Messages("FeuilleDeResultat",defaultLocale));
		// TODO Auto-generated constructor stub
		interpret = new InterpretationLogic(defaultLocale,"FeuilleDeResultat");
		buildMainLayout();
		setCompositionRoot(mainLayout);
		
	}
	
	public PersonBean getFirstPerson() {
		return firstPerson;
	}

	public void setFirstPerson(PersonBean firstPerson) {
		this.firstPerson = firstPerson;
	}

	public PersonBean getSecondPerson() {
		return secondPerson;
	}

	public void setSecondPerson(PersonBean secondPerson) {
		this.secondPerson = secondPerson;
	}

	public Label getResultLabel() {
		return resultLabel;
	}

	public Messages getMessages() {
		return messages;
	}


	public void setMessages(Messages messages) {
		this.messages = messages;
	}
	
	public InterpretationLogic getInterpret() {
		return interpret;
	}

	public void setInterpret(InterpretationLogic interpret) {
		this.interpret = interpret;
	}
	
	public void setResultText(){
		resultLabel.setValue(interpret.interpretCroise());
		resultLabel.requestRepaint();
		mainPanel.requestRepaint();
	}
	
	private AbsoluteLayout buildMainLayout(){
		mainLayout = new AbsoluteLayout();
		mainLayout.setImmediate(true);
		
		mainLayout.setWidth("510px");
		mainLayout.setHeight("310%");
		mainLayout.setMargin(false);
		
		// top-level component properties
		setWidth("550.0px");
		setHeight("350.0px");
		
		//add result Panel
		mainPanel = new Panel(this.messages.getString("feuilleCaption"));
		mainPanel.setImmediate(true);
		mainPanel.setWidth("505px");
		mainPanel.setHeight("310px");
		mainPanel.getContent().setSizeUndefined();
		
		//result text label
		resultLabel = new Label();
		resultLabel.setImmediate(true);
		resultLabel.setWidth("500px");
		resultLabel.setHeight("300px");
				
		resultLabel.setContentMode(Label.CONTENT_RAW);
		mainPanel.addComponent(resultLabel);
		//intrepratation source label
		sourceLabel = new Label();
		mainPanel.addComponent(sourceLabel);
		
		mainLayout.addComponent(mainPanel, "top:0.0px;left:0.0px;");
		
		//resultLabel.setValue(interpret.i)
		return mainLayout;
	}
	
	
}
